package com.example.exam.conf.security;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.exam.entity.User;
import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhang
 */
@Repository
public interface UserRepository extends JpaRepository<User, Long>{
    @Query(value = "SELECT\n" +
            "`user`.id,\n" +
            "`user`.account,\n" +
            "`user`.`name`,\n" +
            "`user`.`password`,\n" +
            "`user`.time,\n" +
            "`user`.`status`,\n" +
            "`user`.sex,\n" +
            "`user`.age,\n" +
            "`user`.email,\n" +
            "`user`.salt,\n" +
            "`user`.idcard,\n" +
            "`user`.nickname,\n" +
            "user_roles.user_id,\n" +
            "user_roles.role_id\n" +
            "FROM\n" +
            "`user` ,\n" +
            "user_roles\n" +
            "WHERE\n" +
            "user.id = user_roles.user_id and account = ?1", nativeQuery = true)
    List<User> findByAccount(String account);
}
